//
//  YXLHomeNotifyView.m
//  MyNewProject
//
//  Created by 于兴雷 on 2019/1/29.
//  Copyright © 2019年 sun. All rights reserved.
//

#import "YXLHomeNotifyView.h"
#import "YXLHomeNotifyInfoView.h"

@interface YXLHomeNotifyView()


@property (nonatomic , weak) YXLHomeNotifyInfoView *infoViewOne;

@property (nonatomic , weak) YXLHomeNotifyInfoView *infoViewTwo;

//@property (nonatomic , weak) YXLHomeNotifyInfoView *infoViewThree;


@end


@implementation YXLHomeNotifyView

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.currentNum = 0;
//        
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapView)];
//        
//        [self addGestureRecognizer:tap];
        
        //self.dataArry = @[@"",@"",@"",@"",@"",@"",@"",@"",@""];
        
        [self initView];
    }
    
    return self;
}

-(void)tapView
{
    NSLog(@"tapViewtapView");
}

-(void)initView
{
    
    YXLHomeNotifyInfoView *infoViewOne = [[YXLHomeNotifyInfoView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [self addSubview:infoViewOne];
    self.infoViewOne = infoViewOne;
    
    YXLHomeNotifyInfoView *infoViewTwo = [[YXLHomeNotifyInfoView alloc] initWithFrame:CGRectMake(0, self.frame.size.height, self.frame.size.width, self.frame.size.height)];
    [self addSubview:infoViewTwo];
    self.infoViewTwo = infoViewTwo;
    
    
//    self.infoViewOne.contentLab.text = @"关于提现通知";
//    
//    self.infoViewTwo.contentLab.text = [NSString stringWithFormat:@"%d",self.currentNum + 1];
    
    //self.infoViewThree.contentLab.text = [NSString stringWithFormat:@"%d",self.currentNum + 1];
    
    //[self performSelector:@selector(runNotify) withObject:self afterDelay:1];
}



-(void)runNotify
{
    
    if (self.dataArry.count == 1) {
        
        self.infoViewOne.contentLab.text = self.dataArry[0];
        return;
    }
    
    
    
    if (self.currentNum > self.dataArry.count-1) {
        self.currentNum = 0;
    }
    
//    NSMutableArray * notifyTitleArry = [[NSMutableArray alloc] initWithCapacity:0];
//
//    for (NSDictionary *dic in self.dataArry) {
//        NSString *titleStr = [dic stringWithFilted:@"title"];
//        [notifyTitleArry addObject:titleStr];
//    }
    NSDictionary *dic =  self.dataArry[self.currentNum];
    
    NSString *titleStr = SafeString(dic[@"title"]) ;
    
    self.infoViewOne.contentLab.text = titleStr;
    
    [UIView animateWithDuration:1.5 animations:^{

        self.infoViewOne.frame = CGRectMake(0, -self.frame.size.height, self.frame.size.width, self.frame.size.height);
        self.infoViewTwo.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
        
    } completion:^(BOOL finished) {
        
        self.infoViewOne.frame = CGRectMake(0, self.frame.size.height, self.frame.size.width, self.frame.size.height);
        YXLHomeNotifyInfoView *infoViewOne = self.infoViewOne;
        self.infoViewOne = self.infoViewTwo;
        self.infoViewTwo = infoViewOne;

        
        self.currentNum += 1;
        [self runNotify];
    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
